/**==============================================================================
            Copyright (c) 2013 Moritz Hader, Marcel Schrder
            All Rights Reserved.

	@file  DynamicElement.java

	@brief Browser intern representation of a Dynamic Element from the IS
   
   This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

==============================================================================*/
package de.ibm.dhbw.backing.dataHolding;

import java.util.logging.Logger;


/**
 * @author Marcel Schroeder - marcel_schroeder89@hotmail.com
 */
public class DynamicElementObject extends ElementObject {
	private static Logger Log = Logger.getLogger(DynamicElementObject.class.getCanonicalName());
	
	
	
	//----------- Properties and Constructor -----------//

	private float movement;
	
	public DynamicElementObject(int id, int type, float IS_posX, float IS_posY, float directionX, float directionY, Marker marker) {
		super(id, type, IS_posX, IS_posY, directionX, directionY, marker);
		
		
		
		this.movement = (float) Math.sqrt(Math.pow(directionX, 2) + Math.pow(directionY, 2));
		
	}
	
	
	//----------- External Methods -----------//
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		String element = "DynamicElement id:" + this.getId() + ", IS-Position x:" + this.getIS_posX() + "|y:" + this.getIS_posY() + ", ARB-Position x:" + this.getARB_posX() + "|y:" + this.getARB_posY() + ", MarkerId:" + this.getMarker().getId() + ", Speed:" + this.movement + ", Target: <undefined>" + ", Type:" + this.getType();
		return element;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object object) {
		if(object instanceof DynamicElementObject) {
			DynamicElementObject comp = (DynamicElementObject) object;
			if(this.getId() == comp.getId() 
					&& this.getType() == comp.getType() 
					&& this.getIS_posX() == comp.getIS_posX() 
					&& this.getIS_posY() == comp.getIS_posY()
					&& this.getDirectionInDegrees() == comp.getDirectionInDegrees()
					&& this.movement == comp.getMovement()
					&& this.getDirectionX() == comp.getDirectionX()
					&& this.getDirectionY() == comp.getDirectionY()
					&& this.getMarker().getId() == comp.getMarker().getId()) {
				return true;
			}
		}
		return false;
	}
	
	
	//----------- External Methods -----------//

	public void interpolateNewPosition(float timePassedInSec) {
		this.setIS_posX(this.getIS_posX() + (this.getDirectionX() * timePassedInSec));
		this.setIS_posY(this.getIS_posY() + (this.getDirectionY() * timePassedInSec));
		this.setARB_posX(this.getIS_posX() - this.getMarker().getIS_posX());
		this.setARB_posY(this.getIS_posY() - this.getMarker().getIS_posY());
	}
	
	
	//----------- Simple Getter and Setter -----------//

	public float getMovement() {
		return movement;
	}
}
